User Op
UserOperation (UserOp) Structure
The UserOperation struct is a fundamental component of the Account Abstraction system. Here's the detailed structure with explanations:
struct UserOperation {
address sender; // The account making the operation
uint256 nonce; // Anti-replay parameter
bytes initCode; // Code to create new account (empty for existing)
bytes callData; // The data to pass to the sender during execution
uint256 callGasLimit; // Gas limit for the main execution call
uint256 verificationGasLimit; // Gas limit for the verification step
uint256 preVerificationGas; // Extra gas to pay the bundler
uint256 maxFeePerGas; // Maximum fee per gas (similar to EIP-1559)
uint256 maxPriorityFeePerGas; // Maximum priority fee per gas
bytes paymasterAndData; // Paymaster address and data (if used)
bytes signature; // Data to verify authorization
}
Differences between UserOp v6 and PackedUserOp v7
-
Structure and Packing:
- v6 UserOp: Used the full structure as shown above.
- v7 PackedUserOp: Introduces a more gas-efficient packed version for on-chain use.
-
Field Consolidation in v7:
initCode
: Combinesfactory
andfactoryData
into a singlebytes
field.accountGasLimits
: PacksverificationGasLimit
andcallGasLimit
into a singlebytes32
.gasFees
: CombinesmaxPriorityFeePerGas
andmaxFeePerGas
into a singlebytes32
.paymasterAndData
: Consolidates all paymaster-related fields.
-
Paymaster Handling:
- v6: Separate fields for paymaster address and data.
- v7: Combines paymaster information into
paymasterAndData
.
-
Gas Limit Representation:
- v6: Separate
uint256
fields for different gas limits. - v7: Uses packed
bytes32
for gas limits, improving gas efficiency.
- v6: Separate
-
Nonce Management:
- v6: Basic nonce field.
- v7: May include improvements in nonce handling (though not explicitly changed in the struct) may Add validator to be used as a key.
-
Signature Field:
- Remains similar in both versions, but v7 might have enhanced security considerations.
PackedUserOp v7 Structure
Here's a representation of how the PackedUserOp in v7 might look:
struct PackedUserOperation {
address sender;
uint256 nonce;
bytes initCode;
bytes callData;
bytes32 accountGasLimits; // Packed verificationGasLimit and callGasLimit
uint256 preVerificationGas;
bytes32 gasFees; // Packed maxPriorityFeePerGas and maxFeePerGas
bytes paymasterAndData;
bytes signature;
}
Key Improvements in v7
-
Gas Efficiency: The packed structure in v7 reduces the gas cost for storing and processing UserOperations on-chain.
-
Simplified On-Chain Handling: By consolidating fields, v7 simplifies the process of unpacking and using the data within smart contracts.
-
Flexibility: The packed format allows for easier future extensions without changing the core structure.
-
Optimized Storage: Reduces the storage footprint of UserOperations in contract memory and storage.
These changes in v7 reflect a focus on optimizing gas usage and improving the overall efficiency of the Account Abstraction system, while maintaining the core functionality established in v6.
Refer to EIP 4337 Using Alt Mempool for better Understanding